/* file nd_app.h
 * nd engine server application interface
 *
 * neil duan
 * 2008-6
 */

#pragma warning(disable: 4819)

#ifndef _ND_APP_H_
#define _ND_APP_H_

#include "nd_common/nd_common.h"
#include "nd_net/nd_netlib.h"
#include "nd_crypt/nd_crypt.h"
#include "nd_srvcore/nd_srvlib.h"

#include "nd_app/nd_appdef.h"
#include "nd_app/app_msgid.h"


struct srv_config
{
	NDINT32 port ;
	NDINT32 max_connect ;
	NDINT8 listen_name[32] ;
};

#define ND_CUR_VERSION 0x1		


CPPAPI ndchar_t *srv_getconfig() ;

CPPAPI NDINT32 read_config(NDINT8 *file, struct srv_config *readcfg) ;

CPPAPI NDINT32 init_server_app(struct srv_config *run_config) ;

CPPAPI void destroy_rsa_key();

CPPAPI ND_RSA_CONTEX  *get_rsa_contex();

CPPAPI NDINT8 *get_pubkey_digest() ;	

CPPAPI NDINT32 start_server(NDINT32 argc, NDINT8 *argv[]);

CPPAPI NDINT32 end_server(NDINT32 force);

CPPAPI NDINT32 wait_services() ;


CPPAPI nd_handle get_listen_handle() ;


CPPAPI NDINT32 create_rsa_key() ;

CPPAPI nd_thsrvid_t get_timer_thid() ;

/* set player size*/
CPPAPI void set_session_size(size_t size) ;
CPPAPI struct cm_manager * get_cm_manager() ;

static __INLINE__ void nd_pause()
{
	getch() ;
	ndprintf("press ANY key to continue\n") ;
}

MSG_ENTRY_DECLARE(srv_echo_handler) ;
//extern NDINT32 srv_echo_handler(nd_handle session_handle , nd_usermsgbuf_t *msg, nd_handle h_listen) ;
MSG_ENTRY_DECLARE(srv_broadcast_handler) ;
//extern NDINT32 srv_broadcast_handler(nd_handle session_handle , nd_usermsgbuf_t *msg, nd_handle h_listen) ;

//CPPAPI NDINT32 srv_echo_handler(nd_handle session_handle , nd_usermsgbuf_t *msg, nd_handle h_listen) ;

//CPPAPI NDINT32 srv_broadcast_handler(nd_handle session_handle , nd_usermsgbuf_t *msg, nd_handle h_listen) ;

CPPAPI void install_start_session(nd_handle listen_handle);

#ifndef WIN32
CPPAPI NDINT32 installed_sig_handle(void);

CPPAPI NDINT32 wait_signal_entry();

CPPAPI NDINT32 block_signal(void) ;

NDINT8 *get_signal_desc(NDINT32 signo);
CPPAPI NDINT32 unblock_signal(void) ;
CPPAPI NDINT32 ignore_all_signal(void) ;
#endif //WIN32


#endif
